package com.shiliao.app.activity.personal.ui;

import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.View;

import com.shiliao.app.R;
import com.shiliao.app.activity.personal.presenter.MessagePresenter;
import com.shiliao.app.activity.personal.view.MessageView;
import com.shiliao.app.event.MessageEvent;
import com.shiliao.app.manager.YMUserManager;
import com.shiliao.app.utils.WebSetUtil;
import com.shiliao.app.utils.YMServerUtil;
import com.shiliao.app.weight.ActionBarView;
import com.shiliao.app.weight.ProgressWebView;
import com.yimei.framework.base.ui.BaseActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;

/**
 * Created by yinzhiqiang on 2017/10/10.
 */

public class MessageActivity extends BaseActivity implements MessageView {

    @BindView(R.id.webview)
    ProgressWebView webview;

    @BindView(R.id.title_bar)
    ActionBarView mActionBar;

    private MessagePresenter messagePresenter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_message;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void initView() {
        super.initView();
        mActionBar.setTitles("我的消息");
        mActionBar.setBackClick(this);
        mActionBar.getBackView().setVisibility(View.VISIBLE);
        messagePresenter = new MessagePresenter(this);
        String userId = YMUserManager.getUserId(this);
        messagePresenter.requestMessage(userId);
        WebSetUtil.setWebView(webview);
    }


    @Override
    public void getContent(final String content) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                webview.loadDataWithBaseURL(YMServerUtil.BASE_URL,
                        content, "text/html", "utf-8", null);
                YMUserManager.bHasnewmessage = false;
                MessageEvent mEvent = new MessageEvent();
                mEvent.eventId = MessageEvent.EVENT_ID_NEW_MSG_STATUS_CHANGE;
                EventBus.getDefault().post(mEvent);

            }
        });
    }
}
